﻿Public Class frmProtocolo

    Private gestorProcotolo As New BLprotocolo
    Private codPatrocinador As Integer
    Private codInvestigador As Integer

    Private Sub cargarDatos()

        Try
            Me.cmbTipo.Items.Add("Cualquiera")
            Me.cmbTipo.DataSource = gestorProcotolo.ListarTipoProtocolo
            Me.cmbTipo.DisplayMember = "nombre"
            Me.cmbTipo.ValueMember = "id_tipo"
            Me.cmbTipo.SelectedIndex = 0

            Me.cmbEstado.DataSource = gestorProcotolo.ListarEstados
            Me.cmbEstado.DisplayMember = "nombre"
            Me.cmbEstado.ValueMember = "id_estado"
            Me.cmbEstado.SelectedIndex = 0

        Catch ex As Exception

            MsgBox(ex.ToString)

        End Try
    End Sub

    Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click
        dgvProtocolo.DataSource = gestorProcotolo.Buscar(Me.txtCodigo.Text, Me.txtNombre.Text, Me.codPatrocinador, Me.codInvestigador, _
                               Me.dtpInicio.Value, Me.dtpFin.Value, Me.cmbTipo.SelectedValue, Me.cmbEstado.SelectedValue)
        dgvProtocolo.Columns("codigo").HeaderText = "Código"
        dgvProtocolo.Columns("titulo").HeaderText = "Título"
        dgvProtocolo.Columns("patrocinador").HeaderText = "Patrocinador"
        dgvProtocolo.Columns("investigador").HeaderText = "Investigador"
        dgvProtocolo.Columns("estado").HeaderText = "Estado"


    End Sub


    Private Sub btnAgregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgregar.Click
        frmManProtocolo.Show()
    End Sub

    Private Sub frmProtocolo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.cargarDatos()
    End Sub

    Private Sub btnBuscarPatrocinador_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscarPatrocinador.Click

        frmPatrocinador.ShowDialog()
        Me._codPatrocinador = frmPatrocinador._codPatrocinador
        Me.txtPatrocinador.Text = frmPatrocinador._nomPatrocinador

    End Sub

    Public Property _codPatrocinador() As String
        Get
            Return codPatrocinador
        End Get
        Set(ByVal value As String)
            Me.codPatrocinador = value
        End Set
    End Property

    Public Property _codInvestigador() As Integer
        Get
            Return Me.codInvestigador
        End Get
        Set(ByVal value As Integer)
            Me.codInvestigador = value
        End Set
    End Property

    Private Sub btnBuscarResponsable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscarResponsable.Click
        frmMedicos.ShowDialog()
        Me._codInvestigador = frmMedicos._codMedico
        Me.txtResponsable.Text = frmMedicos._nomMedico
    End Sub

    Private Sub btnSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalir.Click
        Me.Close()
    End Sub
End Class